/// 打卡记录模型
class CheckinRecordModel {
  final String id;
  final String userId;
  final DateTime date;
  final bool isChecked;

  CheckinRecordModel({
    required this.id,
    required this.userId,
    required this.date,
    required this.isChecked,
  });

  /// 从 JSON 创建打卡记录模型
  factory CheckinRecordModel.fromJson(Map<String, dynamic> json) {
    return CheckinRecordModel(
      id: json['id'] as String,
      userId: json['userId'] as String,
      date: DateTime.parse(json['date'] as String),
      isChecked: json['isChecked'] as bool,
    );
  }

  /// 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'userId': userId,
      'date': date.toIso8601String(),
      'isChecked': isChecked,
    };
  }

  /// 复制打卡记录模型并修改部分属性
  CheckinRecordModel copyWith({
    String? id,
    String? userId,
    DateTime? date,
    bool? isChecked,
  }) {
    return CheckinRecordModel(
      id: id ?? this.id,
      userId: userId ?? this.userId,
      date: date ?? this.date,
      isChecked: isChecked ?? this.isChecked,
    );
  }

  @override
  String toString() {
    return 'CheckinRecordModel(id: $id, userId: $userId, date: $date, isChecked: $isChecked)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is CheckinRecordModel && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;
}
